home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / modex32w.zip / MEM2SC.ASM < prev    next >
Assembly Source File  |  1995-02-21  |  6KB  |  128 lines

  1.         .386p
  2.         locals
  3.         include w.inc
  4.  
  5. ; Mode X (320x240, 256 colors) system memory to display memory copy
  6. ; routine. Uses approach of changing the plane for each pixel copied;
  7. ; this is slower than copying all pixels in one plane, then all pixels
  8. ; in the next plane, and so on, but it is simpler; besides, images for
  9. ; which performance is critical should be stored in off-screen memory
  10. ; and copied to the screen via the latches. Copies up to but not
  11. ; including the column at SourceEndX and the row at SourceEndY. No
  12. ; clipping is performed. C near-callable as:
  13. ;    void CopySystemToScreenX(int SourceStartX, int SourceStartY,
  14. ;       int SourceEndX, int SourceEndY, int DestStartX,
  15. ;       int DestStartY, char* SourcePtr, unsigned int DestPageBase,
  16. ;       int SourceBitmapWidth, int DestBitmapWidth);
  17.  
  18. SC_INDEX equ    03c4h   ;Sequence Controller Index register port
  19. MAP_MASK equ    02h     ;index in SC of Map Mask register
  20.  
  21. parms   struc
  22.         dd      2 dup (?) ;pushed BP and return address
  23. SourceStartX dd ?       ;X coordinate of upper left corner of source
  24. SourceStartY dd ?       ;Y coordinate of upper left corner of source
  25. SourceEndX   dd ?       ;X coordinate of lower right corner of source
  26.                         ; (the row at EndX is not copied)
  27. SourceEndY   dd ?       ;Y coordinate of lower right corner of source
  28.                         ; (the column at EndY is not copied)
  29. DestStartX   dd ?       ;X coordinate of upper left corner of dest
  30. DestStartY   dd ?       ;Y coordinate of upper left corner of dest
  31. SourcePtr    dd ?       ;pointer in DS to start of bitmap in which
  32.                         ; source resides
  33. DestPageBase dd ?       ;base offset in display memory of page in
  34.                         ; which dest resides
  35. SourceBitmapWidth dd ?  ;# of pixels across source bitmap
  36. DestBitmapWidth   dd ?  ;# of pixels across dest bitmap
  37.                         ; (must be a multiple of 4)
  38. parms   ends
  39.  
  40. RectWidth equ   -4      ;local storage for width of rectangle
  41. LeftMask equ    -6      ;local storage for left rect edge plane mask
  42. STACK_FRAME_SIZE equ 6
  43.  
  44.         @dseg
  45.  
  46.         extrn   SCREEN_SEG:dword
  47.  
  48.         ends
  49.  
  50.         @cseg
  51.  
  52.         public  _CopySystemToScreenX
  53. _CopySystemToScreenX proc    near
  54.         push    ebp      ;preserve caller's stack frame
  55.         mov     ebp,esp   ;point to local stack frame
  56.         sub     esp,STACK_FRAME_SIZE ;allocate space for local vars
  57.         push    esi      ;preserve caller's register variables
  58.         push    edi
  59.         push    ebx
  60.  
  61.         cld
  62.         mov     eax,[ebp+SourceBitmapWidth]
  63.         mul     [ebp+SourceStartY] ;top source rect scan line
  64.         add     eax,[ebp+SourceStartX]
  65.         add     eax,[ebp+SourcePtr] ;offset of first source rect pixel
  66.         mov     esi,eax             ; in DS:ESI
  67.         
  68.         mov     eax, [ebp+DestBitmapWidth]
  69.         shr     eax,2            ;convert to width in addresses
  70.         mov     [ebp+DestBitmapWidth],eax ;remember address width
  71.         mul     [ebp+DestStartY] ;top dest rect scan line
  72.         mov     edi, [ebp+DestStartX]    ; clear hi(edi)
  73.         mov     ecx,edi
  74.         shr     edi,2    ;X/4 = offset of first dest rect pixel in scan line
  75.         add     edi,eax   ;offset of first dest rect pixel in page
  76.         add     edi,[ebp+DestPageBase] ;offset of first dest rect pixel
  77.                         ; in display memory
  78.         add     edi,[SCREEN_SEG]  ;make mem ptr now
  79.  
  80.         and     cl,011b ;CL = first dest pixel's plane
  81.         mov     al,11h  ;upper nibble comes into play when plane wraps
  82.                         ; from 3 back to 0
  83.         shl     al,cl   ;set the bit for the first dest pixel's plane
  84.         mov     [ebp+LeftMask],al ; in each nibble to 1
  85.  
  86.         mov     ecx,[ebp+SourceEndX]   ;calculate # of pixels across
  87.         sub     ecx,[ebp+SourceStartX] ; rect
  88.         jle     CopyDone        ;skip if 0 or negative width
  89.         mov     [ebp+RectWidth],ecx
  90.         mov     ebx,[ebp+SourceEndY]
  91.         sub     ebx,[ebp+SourceStartY]  ;BX = height of rectangle
  92.         jle     CopyDone        ;skip if 0 or negative height
  93.         mov     dx,SC_INDEX     ;point to SC Index register
  94.         mov     al,MAP_MASK
  95.         out     dx,al           ;point SC Index reg to the Map Mask
  96.         inc     dx              ;point DX to SC Data reg
  97. CopyRowsLoop:
  98.         mov     ax,[ebp+LeftMask]
  99.         mov     ecx,[ebp+RectWidth]
  100.         push    esi      ;remember the start offset in the source
  101.         push    edi      ;remember the start offset in the dest
  102. CopyScanLineLoop:
  103.         out     dx,al           ;set the plane for this pixel
  104.         movsb                   ;copy the pixel to the screen
  105.         rol     al,1            ;set mask for next pixel's plane
  106.         cmc                     ;advance destination address only when
  107.         sbb     di,0            ; wrapping from plane 3 to plane 0
  108.                                 ; (else undo INC DI done by MOVSB)
  109.         loop    CopyScanLineLoop
  110.         pop     edi      ;retrieve the dest start offset
  111.         add     edi,[ebp+DestBitmapWidth] ;point to the start of the
  112.                                         ; next scan line of the dest
  113.         pop     esi      ;retrieve the source start offset
  114.         add     esi,[ebp+SourceBitmapWidth] ;point to the start of the
  115.                                         ; next scan line of the source
  116.         dec     ebx      ;count down scan lines
  117.         jnz     CopyRowsLoop
  118. CopyDone:
  119.         pop     ebx
  120.         pop     edi      ;restore caller's register variables
  121.         pop     esi
  122.         mov     esp,ebp   ;discard storage for local variables
  123.         pop     ebp      ;restore caller's stack frame
  124.         ret
  125. _CopySystemToScreenX endp
  126.         ends
  127.         end
  128.